---
title: "Table A.8"
output: 
---

# Table A.8

# Who's to Blame? Postconflict Violence and Public Attitudes Towards Peace Agreements
# Wyer, Frank. 

#clear environment
```{r clear environment}
rm(list = ls())
```

# uncomment and set working directory to replication archive
# setwd("~/blame_replication")

# Uncomment to install packages if necessary
# install.packages("tidyverse")
# install.packages("estimatr")
# install.packages("texreg")


#load packages
```{r}
library(tidyverse)
library(estimatr)
library(texreg)

```

#read in data
```{r}
survey_clean <- read.csv("survey_clean.csv")
```

#clean enumerator variable, creating category for missing enumerator name
```{r enum variable}
survey_clean <- survey_clean %>% mutate(enum_full = ifelse(is.na(Q66), 105, Q66))
```

#lin estimator centers covariates and interacts them with treatment variable
#here, we want to maintain that framework but add fixed effects for enumerators
#this creates some degrees-of-freedom issues given the number of treated units and number of enumerators
#solution: allow enumerators to have effects but do not interact with treatment
#for the region effects, combine the two most similar regions (central and south) 
# center the standard covariates and interact with treatment to manually replicate lin estimator
#add enumerator variable as a fixed effect

#centering covariates for manual lin estimation strategy
```{r center covariates for lin estimation}
survey_clean$age_c <- c(scale(survey_clean$Q15, center = TRUE, scale = FALSE))
survey_clean$ideology_c <- c(scale(survey_clean$Q25, center = TRUE, scale = FALSE))
survey_clean$urban_c <- c(scale(survey_clean$urbandummy, center = TRUE, scale = FALSE))
survey_clean$engage_c <- c(scale(survey_clean$engage_zscale, center = TRUE, scale = FALSE))
survey_clean$farc_c <- c(scale(survey_clean$farc_presence, center = TRUE, scale = FALSE))
survey_clean$homratediff_c <- c(scale(survey_clean$homratediff, center = TRUE, scale = FALSE))
survey_clean$homrate100k_c <- c(scale(survey_clean$homrate100k, center = TRUE, scale = FALSE))

survey_clean <- survey_clean %>% 
mutate(
  southdummy = ifelse(regionname == "Sur", 1, 0), #not used
  caribdummy = ifelse(regionname == "Caribe", 1, 0),
  nwdummy = ifelse(regionname == "Noroccidental", 1, 0),
  nedummy = ifelse(regionname == "Nororiental", 1, 0),
  centraldummy = ifelse(regionname == "Central", 1, 0), #not used
  westdummy = ifelse(regionname == "Occidental", 1, 0),
  eastdummy = ifelse(regionname == "Oriental", 1, 0),
    southcentraldummy = ifelse(regionname == "Sur" | regionname == "Central", 1, 0) #combine south and central regions due to DOF constraints

)

# carribean region as omitted

survey_clean$southdummy_c <- c(scale(survey_clean$southdummy, center = TRUE, scale = FALSE))
survey_clean$southcentraldummy_c <- c(scale(survey_clean$southcentraldummy, center = TRUE, scale = FALSE))

survey_clean$caribdummy_c <- c(scale(survey_clean$caribdummy, center = TRUE, scale = FALSE))
survey_clean$nwdummy_c <- c(scale(survey_clean$nwdummy, center = TRUE, scale = FALSE))
survey_clean$nedummy_c <- c(scale(survey_clean$nedummy, center = TRUE, scale = FALSE))
survey_clean$centraldummy_c <- c(scale(survey_clean$centraldummy, center = TRUE, scale = FALSE))
survey_clean$westdummy_c <- c(scale(survey_clean$westdummy, center = TRUE, scale = FALSE))
survey_clean$eastdummy_c <- c(scale(survey_clean$eastdummy, center = TRUE, scale = FALSE))
```


#replicate main treatment effect models, adding enumerator variable as fixed effect
```{r enum FE models}
index_efe_model <- lm_robust(outcomes_zscale ~ treatment*farc_c + treatment*age_c + treatment*ideology_c + treatment*urban_c + treatment*engage_c + treatment*homratediff_c + treatment*nwdummy_c + treatment*nedummy_c + treatment*southcentraldummy_c + treatment*westdummy_c + treatment*eastdummy_c, fixed_effects = enum_full, data = survey_clean, se_type = "HC2", alpha = .05)

eln_efe_model <- lm_robust(eln_scale ~ treatment*farc_c + treatment*age_c + treatment*ideology_c + treatment*urban_c + treatment*engage_c + treatment*homratediff_c + treatment*nwdummy_c + treatment*nedummy_c + treatment*southcentraldummy_c + treatment*westdummy_c + treatment*eastdummy_c, fixed_effects = enum_full, data = survey_clean, se_type = "HC2", alpha = .05)

dissident_efe_model <- lm_robust(dissident_scale ~ treatment*farc_c + treatment*age_c + treatment*ideology_c + treatment*urban_c + treatment*engage_c + treatment*homratediff_c + treatment*nwdummy_c + treatment*nedummy_c + treatment*southcentraldummy_c + treatment*westdummy_c + treatment*eastdummy_c, fixed_effects = enum_full, data = survey_clean, se_type = "HC2", alpha = .05)

accords_efe_model <-lm_robust(accords_scale ~ treatment*farc_c + treatment*age_c + treatment*ideology_c + treatment*urban_c + treatment*engage_c + treatment*homratediff_c + treatment*nwdummy_c + treatment*nedummy_c + treatment*southcentraldummy_c + treatment*westdummy_c + treatment*eastdummy_c, fixed_effects = enum_full, data = survey_clean, se_type = "HC2", alpha = .05)
```

#Generate Appendix Table
```{r appendix table}
texreg(list(accords_efe_model, eln_efe_model, dissident_efe_model, index_efe_model), custom.coef.map = list("treatmentT1" = "Postconflict Violence Treatment", "treatmentT2A" = "Government Culpability Treatment", "treatmentT2B" = "Rebel Culpability Treatment"), digits = 2, include.ci = FALSE, single.row = FALSE, include.fstatistic = FALSE, include.rmse = FALSE, include.rsquared = FALSE, include.adjrs = FALSE, include.nobs = TRUE, stars = numeric(0), float.pos = "h", caption.above	= TRUE, caption = "Models with Enumerator Fixed Effects")
```